﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using ArmaTuCumpleWeb.Controllers;
using ArmaTuCumpleWeb;

namespace ArmaTuCumpleWeb
{

    public class FileRepository
    {
        public List<FileDescription> GetAllFileDescription()
        {
            string uploadFolder = HttpContext.Current.Server.MapPath("./Uploads");

            String[] nueva = uploadFolder.Split('\\');
            String folder="";
            for (int i = 0; i < nueva.Length; i++)
            {
                if(!nueva[i].Equals("File"))
                {
                    folder=folder+nueva[i]+"\\";
                }
            }
            string[] files = Directory.GetFiles(folder);
            List<FileDescription> fileDescriptions = new List<FileDescription>();

            foreach (string file in files)
            {
                FileInfo fileinfo = new FileInfo(file);
                fileDescriptions.Add(
                    new FileDescription
                    {
                        Name = fileinfo.Name,
                        Size = fileinfo.Length / 1024,
                        WebPath = fileinfo.Name,
                        
                    });
            }

            return fileDescriptions;
        }
    }
}